#include "Operation.h"

class Factory{
public:
	Operation* createOper(char sign)
	{
		Operation* op = 0;
		switch(sign){
			case '+':
				op = new Add();
				break;
			case '-':
				//
				break;
			case '*':
				op = new Mul();
				break;
			case '/':
				//
				break;
			default:
				break;
		}
		return op;
	}
};

//开放封闭： 对拓展开放，对修改关闭

int main(void)
{
	double numA = 0.0, numB = 0.0;
	char sign = '\0';
	cout << "please input: ";
	cin >> numA >> sign >> numB;

	//创建产品
	Factory f;
	Operation* op = f.createOper(sign);
	if(op == 0){
		return -1;
	}

	//设置产品数据
	op->setNumA(numA);
	op->setNumB(numB);

	//获取结果
	double result = op->getResult();

	//输出数据
	cout << numA << " " << sign << " " 
				<< numB << " = " << result << endl;
}
